<?php
	require_once("conexion/conexion.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<link href="Estilos/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="include_js/jquery.js" type="text/javascript"></script>
<script src="include_js/funciones.js" type="text/javascript"></script>
<script src="include_js/jquery.autocomplete.js" type="text/javascript"></script>
<style>
.texto
{
	font-size:14px;
	margin-left:5px;
	font:Verdana, Arial, Helvetica, sans-serif; 
	color:#0066CC;
}
.asterisco
{
	color:#0000FF;
	font-weight:bold;
}
.Normal
{
border:1px solid #D3E4E5;
}
</style>
<script>
var cont1=2;sumatoria=0;
function BorraDatos(dato)
{
	var cadena = dato.substring(8,9);
	//alert(cadena);
    if(cadena=='1')
	{	
		document.form_otros.submit();
		//document.getElementById('btn_VerFactura').disabled = false;
	}
}

function ObtieneTotal(cont)
{
	var obj1 = 'txtCantidad'+cont+'';
	var obj2 = 'txtUnitario'+cont+'';
	var obj3 = 'txtTotal'+cont+'';
	
	cantidad = document.getElementById(obj1).value;
	unitario = document.getElementById(obj2).value;
	//alert(unitario+" "+cantidad);
	if((unitario!="")&&(cantidad!=""))
	{
		unitario = EliminaPuntos(unitario);
		total = Math.round(cantidad*unitario);
		txt = document.getElementById(obj3);
		document.getElementById(obj3).value = total;
		puntitos(txt,total);
	}
}

function EliminarFila(fila)
{
	var Tr = fila;
	while(Tr.nodeName.toLowerCase()!='tr')
	{
		Tr=Tr.parentNode;
	}
	
	var root = Tr.parentNode;
	root.removeChild(Tr);
}

function AgregaFila()
{	
	nuevaFila = document.getElementById("tablaPro").insertRow(-1);
	nuevaFila.id=cont1;
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input id='txtCantidad"+cont1+"' type='text' name='txtCantidad"+cont1+"' size='5'  onfocus='this.select();'/></td>";

	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input id='txtDetalle"+cont1+"' type='text' name='txtDetalle"+cont1+"' size='50' /></td>";
	
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input id='txtUnitario"+cont1+"' type='text' name='txtUnitario"+cont1+"' size='15'  onfocus='this.select();' onkeyup = 'puntitos(this,this.value.charAt(this.value.length-1))'/></td>";
	
	nuevaCelda=nuevaFila.insertCell(-1);
	nuevaCelda.className='Normal';
	nuevaCelda.innerHTML="<td id='"+cont1+"'><input type='button' value='[x]' onclick='EliminarFila(this);'/></td>";
	document.getElementById("txtCant").value = cont1;
	cont1++;
}

function VerFactura()
{
	rut = document.getElementById('cmb_Cliente').value;
	fac = document.getElementById('txtOrden').value;
	window.open('Contabilidad/Genera_FacCompra.php?rut='+rut+"&fac="+fac,'Ventana','width=700,height=500,scrollbars=YES');
}
</script>
</head>

<body>
<form name="form_otros" id="form_otros" method="post">
<div class='option2'>
  <label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Ingresar Guia de Despacho</label>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="uno">
<tr><td class="Normal" colspan="4"><div style="float:right; clear:none; margin-right:10px; 

margin-top:5px;"><label style="color:#0000FF; font-size:12px; font-weight:bold;">Datos 

Obligatorios(*)</label></div></td></tr>
  <tr>
    <td class="Normal" colspan="4"><hr /></td>
  </tr>
   <tr>
     <td class="Normal"><label class="texto">N&deg; Guia:</label></td>
     <td class="Normal"><input name="txtNum" id="txtNum" type="text" />&nbsp;<label class="asterisco">*</label></td>
     <td class="Normal">&nbsp;</td>
     <td class="Normal">&nbsp;</td>
   </tr>
   <tr>
    <td class="Normal"><label class="texto">Fecha:</label></td>
    <td width="58%" class="Normal"><input name="txtFechaIni" type="text" id="txtFechaIni" size="10">&nbsp;<img src="imagen/img.gif" width="20" height="14" title="calendario" style="cursor: pointer; border: 1px solid green;" onmouseover="this.style.background='black';" onmouseout="this.style.background=''" onclick="popUpCalendar(txtFechaIni, form_otros.txtFechaIni, 'dd-mm-yyyy');" />
      <label class="asterisco">*</label></td>
    <td width="10%" class="Normal">&nbsp;</td>
    <td width="20%" class="Normal"><input type="hidden" name="txtCant" id="txtCant" value="1" /></td>
    </tr>
  <tr>
    <td width="12%" class="Normal"><label class="texto">Se&ntilde;or:</label></td>
    <td class="Normal"><input name="txtPersona" id="txtPersona" type="text" size="70" />&nbsp;<label class="asterisco">*</label></td>
	<td class="Normal"><label class="texto">Rut:</label></td>
	<td class="Normal"><input name="txtRut" id="txtRut" type="text" /></td>
	</tr>
  

  <tr>
    <td class="Normal"><label class="texto">Direcci&oacute;n:</label></td>
    <td class="Normal"><input type="text" name="txtDir" id="txtDir" size="70" /></td>
	<td class="Normal"><label class="texto">Ciudad:</label></td>
	<td class="Normal"><input name="txtCiudad" id="txtCiudad" type="text" /></td>
    </tr>
  <tr>
    <td class="Normal"><label class="texto">Giro:</label></td>
    <td class="Normal"><input type="text" name="txtGiro" id="txtGiro" size="70" /></td>
    <td class="Normal"><label class="texto">Fono:</label></td>
    <td class="Normal"><input name="txtFono" id="txtFono" type="text" /></td>
  </tr> 
  <tr>
    <td class="Normal" colspan="4">&nbsp;</td>
  </tr>
  <tr>
  	<td class="Normal">&nbsp;</td>
  	<td colspan="3" class="Normal">
	 <table border="0" cellpadding="0" cellspacing="0" id="tablaPro">
  <thead>
  <tr>
  	<th>cant.</th>
	<th>detalle</th>
	<th>p. unitario</th>
	<th title="Agrega Nuevo Items"><a href="javascript:AgregaFila();">[+]</a></th>
  </tr>
  
  <tr>
  	<td class="borde"><input name="txtCantidad1" id="txtCantidad1" type="text" size="5" onfocus="this.select();"/></td>
  	<td class="borde"><input name="txtDetalle1" id="txtDetalle1" type="text" size="50"/></td>
	<td class="borde"><input name="txtUnitario1" id="txtUnitario1" type="text" size="15" onfocus="this.select();" onkeyup = "puntitos(this,this.value.charAt(this.value.length-1))"/></td>
	<td class="Normal" style="vertical-align:middle;">&nbsp;<label class="asterisco">*</label></td>
  </tr>
  </thead>
  </table>	</td>
  </tr>
  <tr>
    <td class="Normal">&nbsp;</td>
    <td class="Normal">&nbsp;</td>
    <td class="Normal">&nbsp;</td>
    <td class="Normal">&nbsp;</td>
  </tr>
  <tr>
    <td class="Normal" colspan="4" style="text-align:center"><input type="button" name="btn_Guardar" id="btn_Guardar" value=" " class="guardar" /></td>
  </tr>
	<tr><td class="Normal" colspan="4">&nbsp;</td></tr>
</table>
<div id="mensaje"></div>
</form>

</body>
<script>
$('#btn_Guardar').click(function() 
{ 
        $.ajax({
            type: 'POST',
            url: 'Contabilidad/Ingresa_GuiaDespacho.php',
            data: $('#form_otros').serialize(),
            success: function(data) {
                $('#mensaje').html(data);
				BorraDatos(data);
            }
        })
});
</script>
</html>
